# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module Provider
  module Ansible
    # Contains all information about Ansible tests.
    class Tests < Api::Object
      attr_reader :has_autogenerated_test
      attr_reader :tests
      def validate
        check :has_autogenerated_test, type: :boolean, default: true
        check :tests, type: Array, item_type: Provider::Ansible::Test, default: []

        return unless @has_autogenerated_test

        tests << Test.new('autogen', 'templates/ansible/integration_test.erb') \
          unless @tests.any? { |t| t.name == 'autogen' }
      end
    end

    # Contains information about an individual Ansible test.
    class Test < Api:: Object
      # The filename of the Ansible test playbook (without extension)
      attr_reader :name

      # The path of the test file / test template in MM.
      attr_reader :path

      def initialize(name, path)
        @name = name
        @path = path
      end

      def validate
        check :name, required: true, type: String
        check :path, required: true, type: String
      end
    end
  end
end
